package com.controller;

import com.sun.entity.User;
import com.sun.web.controller.LoginController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by pullFoot_youth on 2017/3/9.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = {"classpath:/springConfigs/spring-dataSource.xml",
        "classpath:/springConfigs/spring-mybatis.xml", "classpath:/springConfigs/spring-jpa.xml",
        "classpath:/springConfigs/spring-mvc.xml"})
public class MockTest1 {

    //模拟 request response
    private MockHttpServletRequest request;
    private MockHttpServletResponse response;

    @Autowired
    private LoginController loginController;

    @Before
    public void setUp(){

        request = new MockHttpServletRequest();

        request.setCharacterEncoding("utf-8");

        response = new MockHttpServletResponse();
    }

    @Test
    public void test(){

        request.setParameter("uesrName","zhangsan");
        request.setParameter("passWord","83483");

        User user = new User();

        user.setUserName("kdjfkd");
        user.setPassWord("kdfjkd");

        User u = (User)loginController.index(user);

        System.out.println(u.getUserName());

    }
}
